package com.gt.web.srv.web.api.ss;

import com.github.pagehelper.PageInfo;
import com.gt.web.api.common.R;
import com.gt.web.srv.service.RepairApplicationService;
import com.gt.web.srv.web.api.command.RepairApplicationCommand;
import com.gt.web.srv.web.api.resource.ss.RepairApplicationResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author jh
 * @Date 2024/5/25 16:40
 * @PackageName:com.gt.web.srv.web.api
 * @ClassName: BizConsultController
 * @Description: 我要咨询controller
 */
@Slf4j
@RestController
@RequestMapping("/repairApplication/")
@Api(tags = "维修单接口")
public class RepairApplicationController {

    @Autowired
    private RepairApplicationService repairApplicationService;

    @ApiOperation(value = "新增", notes = "新增",position = 1)
    @PostMapping("insert")
    public R insert(@RequestHeader("token") String token, @Validated @RequestBody RepairApplicationCommand cmd) {
        return repairApplicationService.insert(cmd);
    }

    @ApiOperation(value = "根据ID查询详情", notes = "根据ID查询详情",position = 2)
    @GetMapping("selectById")
    public R selectById(@RequestHeader("token") String token, @RequestParam(name = "repairId") Long repairId) {
        return repairApplicationService.selectById(repairId);
    }

    @ApiOperation(value = "根据ID更新信息", notes = "根据ID更新信息",position = 3)
    @PostMapping("updateById")
    public R updateById(@RequestHeader("token") String token, @Validated @RequestBody RepairApplicationCommand cmd) {
        return repairApplicationService.updateById(cmd);
    }

    @ApiOperation(value = "分页查询", notes = "分页查询",position = 4)
    @PostMapping("page")
    public R<PageInfo<RepairApplicationResource>> page(@RequestHeader("token") String token, @Validated @RequestBody RepairApplicationCommand cmd) {
        return repairApplicationService.page(cmd);
    }

    @ApiOperation(value = "更新状态和物流信息", notes = "更新状态和物流信息",position = 5)
    @GetMapping("updateStatusAndTracking")
    public R updateStatusAndTracking(@RequestHeader("token") String token, @RequestParam(name = "repairId")  Long repairId,
                                     @RequestParam(name = "trackingNumber" ,required = false)  String trackingNumber) {
        return repairApplicationService.updateStatusAndTracking(repairId,trackingNumber, null);
    }

}
